package com.ruoyi.hqfinance.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.hqfinance.domain.HqOperateHandlingDetail;
import com.ruoyi.hqfinance.domain.HqOperateHandlingSheetByDay;
import com.ruoyi.hqfinance.domain.vo.HqOperateHandlingDetailVo;
import com.ruoyi.hqfinance.domain.vo.HqOperateHandlingSheetByDayVo;
import com.ruoyi.hqfinance.service.HqOperateHandlingDetailService;
import com.ruoyi.logistic.domain.PageDate;
import com.ruoyi.logistic.domain.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/hq/operateHandling")
@Api(tags = "总部财务-操作装卸费报表")
public class HqOperateHandlingController {
    @Autowired
    private HqOperateHandlingDetailService hqOperateHandlingDetailService;

    @ApiOperation("查全部")
    @GetMapping("/selectAll")
    public R selectAll(PageDate pageDate) {
        List<HqOperateHandlingDetail> handlingDetails = hqOperateHandlingDetailService.selectAll(pageDate);
        if (handlingDetails == null || handlingDetails.size() == 0) {
            return R.fail("暂无数据");
        } else {
            return R.ok(handlingDetails);
        }
    }

    @ApiOperation("添加")
    @PostMapping("/insert")
    public R insert(@RequestBody HqOperateHandlingDetail hqOperateHandlingDetail){
        Boolean isAdd = hqOperateHandlingDetailService.insert(hqOperateHandlingDetail);
        if (isAdd){
            return R.ok("添加成功");
        }else {
            return R.fail("添加失败");
        }
    }

    @ApiOperation("修改")
    @PostMapping("/update")
    public R update(@RequestBody HqOperateHandlingDetail hqOperateHandlingDetail){
        Boolean isUpdate = hqOperateHandlingDetailService.update(hqOperateHandlingDetail);
        if (isUpdate){
            return R.ok("修改成功");
        }else {
            return R.fail("修改失败");
        }
    }

    @ApiOperation("删除")
    @PostMapping("/delete")
    public R delete(Integer id){
        Boolean isDelete = hqOperateHandlingDetailService.deleteById(id);
        if (isDelete){
            return R.ok("删除成功");
        }else {
            return R.fail("删除失败");
        }
    }
    @ApiOperation("搜索")
    @PostMapping("/search")
    public R search(@RequestBody HqOperateHandlingDetailVo vo) {
        List<HqOperateHandlingDetail> handlingDetails = hqOperateHandlingDetailService.search(vo);
        if (handlingDetails == null || handlingDetails.size() == 0) {
            return R.fail("暂无数据");
        } else {
            return R.ok(PageInfo.info(handlingDetails));
        }
    }
    @ApiOperation("汇总-日收费")
    @PostMapping("/collect")
    public R collect(@RequestBody HqOperateHandlingSheetByDayVo vo) {
        List<HqOperateHandlingSheetByDay> sheets = hqOperateHandlingDetailService.collectByDay(vo);
        if (sheets == null || sheets.size() == 0) {
            return R.fail("暂无数据");
        } else {
            return R.ok(PageInfo.info(sheets));
        }
    }

}
